<?php 
use think\helper\Time;
use app\common\service\CommonService;

	function returnCourseSumField( $data, $field = 'points' )
    {
        $points = array_column($data, $field);
        return array_sum($points);
    }

    function returnCourseType( $key )
    {
        $arr = [
            1 => 'bofang',
            2 => 'shoucang',
            3 => 'bianji',
            4 => 'wenben',
        ];
        return $arr[$key];
    }


    function returnCourseFetch( $key )
    {
        $arr = [
            1 => 'video',
            2 => 'challenge',
            3 => 'practice',
            4 => 'document',
        ];
        return $arr[$key];
    }


    function returnCourseZh( $key )
    {
        $arr = [
            1 => '视频',
            2 => '挑战',
            3 => '练习',
            4 => '文档',
        ];
        return $arr[$key];
    }

    function returnTrain( $key )
    {
        $arr = [
            0 => '<span class="uncorr">未批改</span>',
            1 => '<span>挑战成功</span>',
            2 => '<span class="fail">挑战失败</span>',
        ];
        return $arr[$key];
    }


    function returnCoursePractice( $process )
    {
        if ($process <= 0)
        {
            $str = '未开始';
        }
        else if ($process > 0 && $process < 30) {
            $str = '已尝试';
        }
        else if ($process >= 30 && $process < 80) {
            $str = '熟悉';
        }
        else if ($process >= 80 && $process < 100) {
            $str = '熟练';
        }
        else
        {
            $str = '已掌握';
        }
        return $str;
    }

    /**
     * 返回开始结束时间
     */
    function returnStartEnd ($time)
    {
        if ($time  == 1) {

            list($start, $end) = Time::today();

        } else if ($time  == 2) {

            list($start, $end) = Time::dayToNow(7, true);

        } else if ($time  == 3) {

            list($start, $end) = Time::month();

        } else if ($time  == 4) {

            list($start, $end) = Time::lastMonth();

        } else if ($time  == 5) {

            list($start, $end) = Time::year();

        }
        return [date('Y-m-d H:i:s',$start),date('Y-m-d H:i:s',$end)];
    }

    function returnTopNav($str)
    {
        $data = CommonService::getAllNavData();
        $html = '';
        foreach ($data as  $v) {
            $html .= '<li><h4><a href="/course/'.$v['nav_id'].'.html" target="_blank">'.$v['nav_name'].'</a></h4>';
            if ($v['type']) foreach($v['type'] as $key => $type){
                $html .= '<a href="/course/'.$v['nav_id'].'/'.$type['type_id'].'.html" target="_blank"><em>'.($key+1 < 10 ? ('0'.($key+1)) : ($key+1)).'. </em><span>'.$type['type_name'].'</span></a>';

            }
            $html .= '</li>';
        }
        return $html;
    }

    function returnSname($str)
    {
        return substr($str, strpos($str, '：')+3);
    }
?>